package com.bbx.taxi.client.Bean.Message;

import java.util.LinkedList;
import java.util.List;

import org.json.JSONObject;


import com.bbx.api.gclient.GClientBox;
import com.bbx.api.gclient.GMsg;
import com.bbx.api.sdk.model.passanger.Return.Jmsg.Msgs;





/**
 * 推送到每个继承Observer的类，然后在该类判断返回类型是否符合自己，符合的话，执行自己想要的操作
 */
public class Publisher {
	private List<ObserverListener> mObs = new LinkedList<ObserverListener>();
	private static Publisher ins = null;
	public static Publisher getInstance(){
		if(ins == null){
			ins = new Publisher();
		}
		return ins;
	}
	/**
	 * 添加想要推送的类
	 */
	public void addOb(ObserverListener ob){
		if(!mObs.contains(ob)){
			mObs.add(ob);
		}
	}
	/**
	 * 移除要推送的类
	 */
	public void removeOb(ObserverListener ob){
		mObs.remove(ob);
	}
	 /**
	 * 推消息送到每个继承Observer类
	 */
	public void publish(int type,JSONObject jb,Msgs.Data msgs_data) {
		 for (int i = 0; i < mObs.size(); i++) {
			 ObserverListener ob = mObs.get(i);
	        	ob.onNotify(type,jb,msgs_data);   	
	        }
	 }
	/**
	 *自定义推送方法
	 */
	public void publish(int type,Object object) {
		 for (int i = 0; i < mObs.size(); i++) {
			 ObserverListener ob = mObs.get(i);
	        	ob.onNotify(type,object);   	
	        }
	 }
	
	/**
	 * 自定义推送方法数据请求的放回结果
	 * @param data_status  请求成功还是失败还是超时 
	 * @param data_type    为请求类型
	 * @param code    返回的状态
	 * @param object  返回类型
	 */
	public void publishdata(ObserverListener.DATA_STATUS data_status,ObserverListener.DATA_TYPE data_type,int status,Object object) {
		for (int i = 0; i < mObs.size(); i++) {
			ObserverListener ob = mObs.get(i);
			ob.onNotifyData(data_status,data_type,status, object);
		}
	}
	public void clear() {
		mObs.clear();
	}
}
